
% allows for batch selection of ROIs

function roi = batchSelectDivingROIs(deinterleave,dosave)

if nargin < 1
    deinterleave = 1;
end
if nargin < 2
    dosave = 1;
end

%% select files:
fn = uigetfile('*.tif','select diving movies','multiselect','on');
if ischar(fn)
    temp = cell(1);temp{1} = fn; fn = temp;
end
nummov = length(fn);

%% iterate through movies and select ROIs
for n = 1:nummov
    movname = fn{n};
    switch deinterleave
        case 0
            mov = loadTiffStack2_SI(fn{n},21:31);
        case 1
            mov = loadTiffStack2_SI(fn{n},21:2:41);
        case 2
            mov = loadTiffStack2_SI(fn{n},22:2:42);
    end
    im = mean(mov,3);
    roi = selectDivingROIs(im);
    if dosave
        savename = strrep(fn{n},'.tif','_selectedROIs.mat');
        save(savename,'roi','movname')
    end
end

